<template>
	<view class="login-tel">
		<view class="tel-main">
			<view class="login-from">
				<view class="login-user">
					<text class="user-name">手机号：</text>
					<input type="number" focus="true" v-model="userTel" value="" placeholder="请输入11位手机号" />
				</view>
			</view>
			<view @click="gologinCode" class="tel">下一步</view>
			<view class="reminder">继续注册表示你阅读并同意<text class="f-active-color">服务协议</text></view>
		</view>
	</view>
</template>

<script>
	import $http from '../../common/api/request.js'
	import Lines from '@/components/common/Lines.vue'
	export default {
		data() {
			return {
				//用户手机号码验证
				userTel:"",
				rules:{
					userTel:{
						// 不能为空
						rule:/^1[3456789]\d{9}$/,
						msg:"请输入11位手机号"
					},
				}
			}
		},
		components:{
			Lines
		},
		methods: {
			// 点击下一步
			gologinCode() {
				if(!this.validate('userTel')) return;
				$http.request({
					url:"/registered",
					method:"POST",
					data:{
						phone:this.userTel,
					}
				}).then((res)=>{
					//存在手机号数据
					if(!res.success){
						uni.showToast({
							title: res.msg,
							icon:'none'
						})
						return ;
					}else{
						//如果不存在
						uni.navigateTo({
							url:'../login-code/login-code?phone='+this.userTel+''
						})
					}
					
				}).catch(()=>{
					uni.showToast({
						title:'请求失败',
						icon:'none'
					})
				})
			},
			//判断验证是否符合规则
			validate(key) {
				let bool = true;
				if(!this.rules[key].rule.test(this[key])) {
					uni.showToast({
						title:this.rules[key].msg,
						icon:"none"
					})
					bool=false;
					return false;
				}
				return bool;
			},
			
		}
	}
</script>

<style scoped>
.login-tel {
	width: 100vw;
	height: 100vh;
}
.tel-main {
	padding: 0 20rpx;
}

.login-from {
	padding-top: 20rpx;
}

.login-user {
	font-size: 32rpx;
	padding: 20rpx 0;
	display: flex;
	align-items: center;
	border-bottom: 2rpx solid #CCCCCC;
}
.user-name {
	padding-right: 5rpx;
}
.reminder {
	color: #636263;
	font-size: 32rpx;
	padding: 20rpx 0;
	text-align: center;
}
.tel {
	margin-top: 20rpx;
	width: 100%;
	height: 80rpx;
	line-height: 80rpx;
	text-align: center;
	color: #FFFFFF;
	background-color: #49BDFB;
	border-radius: 40rpx;
}
</style>
